package com.cs797.project;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.util.Log;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class CircleOverlay extends Overlay {

    private static final String TAG = "CircleOverlay";
    
    private static final float ALPHA_CHANNEL = 80;
    
    Context context;
    GeoPoint location;
    int signalStrength;
    float r;
    float g;
    float b;

    public CircleOverlay(GeoPoint loc, int sigStrength, Context ctx) {
        context = ctx;
        signalStrength = sigStrength;
        location = loc;
    }
    
    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        super.draw(canvas, mapView, shadow);
        
        Point point = new Point();
        Paint paint = new Paint();
        
        Projection projection = mapView.getProjection();
        projection.toPixels(this.location, point);
        
        
        
        paint.setStrokeWidth(1);
        
        r = 255.0f - (((float)Math.abs(signalStrength) - 51f) / (113f - 51f) * 255.0f);
        g = 0.0f;
        b = ((float)Math.abs(signalStrength) - 51f) / (113f - 51f) * 255.0f;
        Log.d(TAG, "Setting Sig: " + signalStrength + " | r: " + r + " | g: " + g + " | b: " + b);
        paint.setARGB((int)ALPHA_CHANNEL, (int)r, (int)g, (int)b);
        
        canvas.drawCircle(point.x, point.y, 5, paint);
        
    }
}
